﻿<%@ WebHandler Language="C#" Class="del" %>
//#define debug

using System;
using System.Web;
using System.Collections.Generic;
using Etong.Web;
public class del : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        //context.Response.ContentType = "text/plain";
        //context.Response.Write("Hello World");
        HttpRequest Request = context.Request;
        string id = Request.QueryString["id"];
        string type = Request.QueryString["type"];
        ConfigTable cTab = ConfigTable.GetThisPageConfigTable();
        string sql = "delete from " + cTab.TableName + " where " + cTab.PkFiledName;
        ConfigColumns pkC = cTab[cTab.PkFiledName];
        if (type == "multy")
        {
            string[] ids = id.Split(',');
            List<string> fixedID = new List<string>();
            foreach (string str in ids)
            {
                fixedID.Add(pkC.GetSqlValueString(str));
            }
            string newIDs = fixedID.ToArray().ToSplitTrimString();

            sql += " in (" + newIDs + ")";
        }
        else
        {
            sql += "=" + pkC.GetSqlValueString(id);
        }
        #if debug
        context.Response.Write(sql);
        #else
        BeforeFactory.BeforeDo(cTab, BeforeType.BeforeDelete, id);
        DBFactory.GetConn().exe0(sql);
        AfterFactory.AfterDo(cTab, AfterType.AfterDelete,id);
        context.Response.Redirect(Request.UrlReferrer.ToString());
        #endif
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}